package com.ly.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class BlockingQueueDemo {

    public static void main(String[] args) throws InterruptedException {
        //add remove 抛出异常
        //offer  -> true false poll -> null
        //put  take 等待
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);

//        System.out.println(blockingQueue.offer("a", 3, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.offer("b", 3, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.offer("c", 3, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.offer("d", 3, TimeUnit.SECONDS));
//
//        System.out.println(blockingQueue.poll(3, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.poll(3, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.poll(3, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.poll(3, TimeUnit.SECONDS));

//        blockingQueue.put("a");
//        blockingQueue.put("a");
//        blockingQueue.put("a");
//        blockingQueue.put("a");

//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());


//        System.out.println(blockingQueue.add("a"));
//        System.out.println(blockingQueue.add("b"));
//        System.out.println(blockingQueue.add("c"));
//        System.out.println(blockingQueue.add("d"));

//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
    }
}
